package com.hongxun.design.listeners;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import com.alibaba.fastjson.JSON;

import com.hongxun.design.MyApp;
import com.hongxun.design.activitys.ChoiceModelActivity;
import com.hongxun.design.activitys.DotDesignActivity;
import com.hongxun.design.activitys.MaterialDetailActivity;
import com.hongxun.design.bean.SetPointInfItemBean;
import com.hongxun.design.constant.Constant;
import com.hongxun.design.mytools.IntentToActivity;
import com.hongxun.design.mytools.MString;
import com.hongxun.design.mytools.ToastShow;

/**
 * Created by zerdoor_pc on 2016/5/18.
 */
public class DesignItemClick implements View.OnClickListener {
    SetPointInfItemBean bean;
    String type;
    String codeset_id;

    public DesignItemClick(SetPointInfItemBean bean, String type, String codeset_id) {
        this.bean = bean;
        this.type = type;
        this.codeset_id = codeset_id;
    }

    @Override
    public void onClick(View view) {
        if (type.equals(MString.ChoiceModelData)) {
            //典设
            if (MyApp.ReadOnly) {
                ToastShow.showShort(MyApp.activity, "暂无权限操作");
            } else {
                Bundle bundle = new Bundle();
                bundle.putString(MString.TYPE, type);
                bundle.putString(MString.ChoiceModelData, JSON.toJSONString(bean));
                bundle.putString(MString.codeset_id, bean.getValueCode());
                bundle.putString(MString.CODE, MString.click_in);
                bundle.putString(MString.filter, ((DotDesignActivity) view.getContext()).getFilter());
                IntentToActivity.intent((DotDesignActivity) view.getContext(), ChoiceModelActivity.class, bundle);
            }
        } else if (codeset_id != null) {
            //材料
            Bundle bundle = new Bundle();
            bundle.putInt(MString.TYPE, Constant.EDIT);
            bundle.putString(MString.codeset_id, codeset_id);
            IntentToActivity.intent((Activity) view.getContext(), MaterialDetailActivity.class, bundle);
        }
    }
}
